package com.sanfeng.smbms.controller;

import com.sanfeng.smbms.common.utils.PageUtils;
import com.sanfeng.smbms.common.utils.R;
import com.sanfeng.smbms.entity.OrderDetailsEntity;
import com.sanfeng.smbms.service.OrderdetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author Nelson
 * @email Nelson@gmail.com
 * 订单详情
 * @date 2022-07-03 17:23:57
 */
@RestController
@RequestMapping("/orderdetails")
public class OrderDetailsController {
    @Autowired
    private OrderdetailsService orderdetailsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderdetailsService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public R listAll() {
        List<OrderDetailsEntity> orderDetailsEntities = orderdetailsService.queryPage();
        return R.ok().put("page", orderDetailsEntities);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{orderdetailid}")
    public R info(@PathVariable("orderdetailid") Integer orderdetailid) {
        OrderDetailsEntity orderdetails = orderdetailsService.getById(orderdetailid);
        return R.ok().put("orderdetails", orderdetails);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public R save(@RequestBody OrderDetailsEntity orderdetails) {
        orderdetailsService.save(orderdetails);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderDetailsEntity orderdetails) {
        orderdetailsService.updateById(orderdetails);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List orderdetailids) {
        orderdetailsService.removeByIds(orderdetailids);
        return R.ok();
    }

}
